# 预编译过程
# https://hub.atomgit.com/repos/amd64/node
FROM hub.atomgit.com/amd64/node@sha256:542d5e86423d063d9999f6a48f1c217a37aafeaa45aca2d1d7139778f262ca05
WORKDIR /app
COPY package.json /app/package.json
COPY ./ /app
RUN  npm config set registry https://registry.npmmirror.com --location=global
RUN npm install --location=global pnpm --registry=https://registry.npmmirror.com
RUN node -v
RUN pnpm  install   
RUN npm run  build

# https://hub.atomgit.com/repos/amd64/node
FROM hub.atomgit.com/amd64/node@sha256:542d5e86423d063d9999f6a48f1c217a37aafeaa45aca2d1d7139778f262ca05
# 配置环境变量
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
# 更换为阿里更新源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 设置时区
RUN apk --update add tzdata \
    && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && apk del tzdata

# 创建app目录
RUN mkdir -p /app
# 设置工作目录
WORKDIR /app
# 持久化日志目录
VOLUME [ "/root/logs" ]
# 为环境配置文件创建挂载点
VOLUME [ "/app/config" ]
# 拷贝所有源代码到工作目录
COPY --from=0 /app /app

# 暴露容器端口
EXPOSE 3000

# 启动node应用，使用挂载的环境配置
CMD export $(grep -v '^#' /app/config/.env | xargs) && node .output/server/index.mjs